package com.kjlink.internal.report4vue.common.controller;

import cn.xuqiudong.common.base.model.BaseResponse;
import cn.xuqiudong.common.base.vo.Select2VO;
import com.kjlink.internal.report4vue.base.controller.BaseApiController;
import com.kjlink.internal.report4vue.base.enums.SelectTypeEnums;
import com.kjlink.internal.report4vue.common.service.ApiCommonService;
import com.kjlink.internal.workreport.base.enums.ReportSelectEnum;
import com.kjlink.internal.workreport.report.service.WorkReportService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * 描述:
 *
 * @author Vic.xu
 * @since 2024-12-05 9:32
 */
@RestController
public class ApiCommonController extends BaseApiController {

    @Resource
    private ApiCommonService apiCommonService;

    @Resource
    private WorkReportService workReportService;

    public ApiCommonController() {
        logger.info("ApiCommonController init");
    }

    /**
     * 枚举下拉框
     */
    @GetMapping("/common/selectEnums/{selectEnum}")
    public BaseResponse<List<Select2VO>> select(@PathVariable ReportSelectEnum selectEnum) {
        List<Select2VO> selectList = selectEnum.toSelectList();
        return BaseResponse.success(selectList);
    }

    /**
     * 一些通用下拉框
     */
    @GetMapping("/common/selectByType/{type}")
    public BaseResponse<List<Select2VO>> select(@PathVariable SelectTypeEnums type) {
        return apiCommonService.select(type);
    }

    /**
     * 查看项目的总工时
     *
     * @param projectId 项目id
     */
    @GetMapping("/common/totalTime/{projectId}")
    public BaseResponse<Integer> totalTime(@PathVariable Integer projectId) {
        Integer totalTime = workReportService.totalTime(projectId);
        return BaseResponse.success(totalTime == null ? 0 : totalTime);
    }
}
